<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
require_once ('./application/controllers/authenticate.php');

class Role extends Authenticate{

    function  __construct() {
        parent::__construct();
        $this->load->model ( 'role_model' );
        $this->load->library ( 'html/control/fx_control' );
        $this->load->library ( 'html/control/fx_filter' );
        $this->load->library ( 'html/control/fx_sort' );
        $this->role_model->addAttributeOrder ( 'id', 'desc' );
    }

    function  _eventLoadLayout() {
        $this->page ['title'] = 'Member Role Management';
        $this->module ['title'] = 'Member Role Management';
        $this->module ['grid'] ['records'] = 20;
        $this->module ['grid'] ['page_range'] = 5;
    }

    function index(){
        $data = $this->_initGridView();
        $this->setPageContent ( 'member/role', $data );
        $this->renderLayout ();
    }

    function _initGridView(){
        $page = $this->input->getParam('page');
        $recordPerPage = $this->input->getParam('recordPerPage');
        if(!$recordPerPage){
            $recordPerPage = $this->module['grid']['records'];
        }
        $filter = $this->input->post('roleFilter');
        $this->fx_filter->filter($filter, $this->role_model);
        $order = $this->input->post('roleOrder');
        $this->fx_sort->sort($order, $this->role_model);
        $found = $this->role_model->countTotal();
        
        $this->load->library ( "tree/paginator/engine/st_paginator_collection" );
        $this->load->library ( "tree/paginator/st_paginator" );
        $this->st_paginator_collection->setModel ( $this->role_model );
        $this->st_paginator->setConfig ( array ('engine' => $this->st_paginator_collection, 'pageRange' => $this->module ['grid'] ['page_range'], 'itemCountPerPage' => $recordPerPage, 'currentPageNumber' => $page ) );
        $collection = $this->st_paginator->getItemsByPage($page);
        if (empty ( $collection )) {
            $collection = array ();
        }
        $data = array();
        $data['found'] = $found;
        $data['sorter'] = $this->fx_sort;
        $data['filter'] = $this->fx_filter;
        $data['paginator'] = $this->st_paginator;
        $data['role_ids'] = $this->input->post('role_ids');
        $data['role_ids_array'] = explode ( ',', $this->input->post ( 'role_ids' ) );
        $data['collection'] = $collection;
        return $data;
    }
}
?>
